from django import forms
from .models import Bus, Driver, Schedule, Maintenance,BusModel

class BusForm(forms.ModelForm):
    model = forms.ModelChoiceField(
        queryset=BusModel.objects.all(),
        label='车型',
        empty_label="请选择车型"
    )

    class Meta:
        model = Bus
        fields = ['bus_id', 'model', 'capacity', 'status']

class DriverForm(forms.ModelForm):
    class Meta:
        model = Driver
        fields = ['driver_id', 'name', 'license', 'status']
        labels = {
            'driver_id': '工号',
            'name': '姓名',
            'license': '驾照类型',
            'status': '状态'
        }
        widgets = {
            'driver_id': forms.TextInput(),
        }


class ScheduleForm(forms.ModelForm):
    class Meta:
        model = Schedule
        fields = ['departure_time', 'bus', 'driver']

        widgets = {
            'departure_time': forms.DateTimeInput(attrs={'type': 'datetime-local'}),
        }

class MaintenanceForm(forms.ModelForm):
    class Meta:
        model = Maintenance
        fields = '__all__'
        widgets = {
            'start_date': forms.DateInput(attrs={'type': 'date'}),
            'end_date': forms.DateInput(attrs={'type': 'date'}),
        }
